get contents
Retrieve TabNews API contents by specifying page number, items per page, and sorting strategy (relevant, new, or old). Streamlines content access for integration projects.
Instructions
get contents from tabnews api
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | The page number to get | |
| per_page | No | The number of contents per page | |
| strategy | No | The strategy to get the contents |
Implementation Reference
- src/tools/status.ts:58-81 (handler)The handler function that executes the logic for the "get contents" tool. It fetches contents via the API service and returns formatted JSON as MCP text content.handler: async (params: GetContentsParams): Promise<McpResponse> => { try { const result = await getContents({ page: params.page, per_page: params.per_page, strategy: params.strategy, }); const content: McpTextContent = { type: "text", text: `Contents:\n\n${JSON.stringify(result, null, 2)}`, }; return { content: [content], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get contents: ${error.message}`); } else { throw new Error("Failed to get contents"); } } },
- src/tools/status.ts:50-57 (schema)Zod schema for input parameters of the "get contents" tool: optional page, per_page, and strategy (relevant/new/old).parameters: { page: z.number().optional().describe("The page number to get"), per_page: z.number().optional().describe("The number of contents per page"), strategy: z .enum(["relevant", "new", "old"]) .optional() .describe("The strategy to get the contents"), },
- src/index.ts:31-36 (registration)Registration of the "get contents" tool with the MCP server by calling server.tool() with name, description, parameters, and handler.server.tool( getContentsTool.name, getContentsTool.description, getContentsTool.parameters, getContentsTool.handler );
- src/services/api.ts:22-37 (helper)Helper function getContents that performs the actual API fetch to TabNews /contents endpoint with pagination and strategy parameters.export async function getContents({ page = 1, per_page = 30, strategy = "relevant", }: GetContentsParams = {}): Promise<TabNewsContent[]> { const queryParams = new URLSearchParams({ page: page.toString(), per_page: per_page.toString(), strategy: strategy, }); const response = await fetch(`${TABNEWS_API_URL}/contents?${queryParams}`); const data = await response.json(); return data as TabNewsContent[]; }
- src/types/index.ts:105-109 (schema)TypeScript interface defining the input parameters for getContents, used in the tool handler and API service.export interface GetContentsParams { page?: number; per_page?: number; strategy?: ContentStrategy; }